<template>
  <a-drawer
    :maskClosable="false"
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
    <erp-omc-task-distribution-form
      ref="realForm"
      @ok="submitCallback"
      :taskId="taskId"
      :projectNameId="projectNameId"
      @unButtonDisable="unButtonDisable"
      :disabled="disableSubmit"
      :isShowCutcontractAmount="true"
      normal></erp-omc-task-distribution-form>
    <div class="drawer-footer">
      <CommonDrawerFooterButton
        startProcess="erpOmcPrepareProject: startProcess"
        :disableSubmit="disableSubmit"
        :buttonDisable="buttonDisable"
        @handleCancel="handleCancel"
        @handleOk="handleOk"
        @beginProcess="beginProcess"
      ></CommonDrawerFooterButton>
    </div>
  </a-drawer>
</template>

<script>

  import ErpOmcTaskDistributionForm from './ErpOmcTaskDistributionForm'
  import CommonDrawerFooterButton from '@/views/components/CommonDrawerFooterButton.vue';
  import { ModalClickMixin } from '@/mixins/ModalClickMixin'
  export default {
    name: 'ErpOmcTaskDistributionModal',
    components: {
      ErpOmcTaskDistributionForm,
      CommonDrawerFooterButton
    },
    props: {
      taskId: {
        type: String,
        default: '',
        required: false
      },
      type: {
        type: String,
        default: '',
        required: false
      },
      projectNameId: {
        type: String,
        default: '',
        required: false
      }
    },
    mixins: [ModalClickMixin],
    data () {
      return {
        mounted: false
      }
    },
    mounted() {
      this.mounted = true
    },
    computed: {
      dialogTrigger() {
        return [this.taskId, this.mounted]
      }
    },
    watch: {
      dialogTrigger() {
        if (!this.mounted) {
          return
        }

        if (this.taskId && this.type === 'assign') {
          this.buttonDisable = false
          this.visible = true
        }
      }
    },
    methods: {
      close () {
        this.$emit('close');
        this.visible = false;
        this.taskId && this.$bus.$emit('update-id-tab')
      },
      submitCallback(type, record) {
        this.$emit('ok', type, record);
        if (type == 'draft') {
          this.visible = false;
          this.taskId && this.$bus.$emit('update-id-tab')
        }
        
      }
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
  .drawer-footer{
    position: absolute;
    bottom: -8px;
    width: 100%;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: right;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
    z-index:9999999
  }
</style>
